<html><!-- Created using the cpp_pretty_printer from the dlib C++ library.  See http://dlib.net for updates. --><head><title>dlib C++ Library - save_jpeg.h</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2014  Davis E. King (davis@dlib.net)
</font><font color='#009900'>// License: Boost Software License   See LICENSE.txt for the full license.
</font><font color='#0000FF'>#ifndef</font> DLIB_SAVE_JPEG_Hh_
<font color='#0000FF'>#define</font> DLIB_SAVE_JPEG_Hh_

<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='save_jpeg_abstract.h.html'>save_jpeg_abstract.h</a>"

<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../enable_if.h.html'>../enable_if.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../matrix.h.html'>../matrix.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../array2d.h.html'>../array2d.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../pixel.h.html'>../pixel.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../image_processing/generic_image.h.html'>../image_processing/generic_image.h</a>"
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>string<font color='#5555FF'>&gt;</font>

<font color='#0000FF'>namespace</font> dlib
<b>{</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='save_jpeg'></a>save_jpeg</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> array2d<font color='#5555FF'>&lt;</font>rgb_pixel<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> img,
        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> filename,
        <font color='#0000FF'><u>int</u></font> quality <font color='#5555FF'>=</font> <font color='#979000'>75</font>
    <font face='Lucida Console'>)</font>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='save_jpeg'></a>save_jpeg</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> array2d<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>char</u></font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> img,
        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> filename,
        <font color='#0000FF'><u>int</u></font> quality <font color='#5555FF'>=</font> <font color='#979000'>75</font>
    <font face='Lucida Console'>)</font>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>typename</font> disable_if<font color='#5555FF'>&lt;</font>is_matrix<font color='#5555FF'>&lt;</font>image_type<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font>::type <b><a name='save_jpeg'></a>save_jpeg</b><font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> image_type<font color='#5555FF'>&amp;</font> img,
        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> filename,
        <font color='#0000FF'><u>int</u></font> quality <font color='#5555FF'>=</font> <font color='#979000'>75</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// Convert any kind of grayscale image to an unsigned char image 
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> image_traits<font color='#5555FF'>&lt;</font>image_type<font color='#5555FF'>&gt;</font>::pixel_type<font color='#5555FF'>&gt;</font>::grayscale<font face='Lucida Console'>)</font>
        <b>{</b>
            array2d<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>char</u></font><font color='#5555FF'>&gt;</font> temp;
            <font color='#BB00BB'>assign_image</font><font face='Lucida Console'>(</font>temp, img<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>save_jpeg</font><font face='Lucida Console'>(</font>temp, filename, quality<font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>else</font>
        <b>{</b>
            <font color='#009900'>// This is some other kind of color image so just save it as an RGB image.
</font>            array2d<font color='#5555FF'>&lt;</font>rgb_pixel<font color='#5555FF'>&gt;</font> temp;
            <font color='#BB00BB'>assign_image</font><font face='Lucida Console'>(</font>temp, img<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>save_jpeg</font><font face='Lucida Console'>(</font>temp, filename, quality<font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> EXP 
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='save_jpeg'></a>save_jpeg</b><font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> matrix_exp<font color='#5555FF'>&lt;</font>EXP<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> img,
        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> file_name,
        <font color='#0000FF'><u>int</u></font> quality <font color='#5555FF'>=</font> <font color='#979000'>75</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        array2d<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> EXP::type<font color='#5555FF'>&gt;</font> temp;
        <font color='#BB00BB'>assign_image</font><font face='Lucida Console'>(</font>temp, img<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>save_jpeg</font><font face='Lucida Console'>(</font>temp, file_name, quality<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<b>}</b>

<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_SAVE_JPEG_Hh_
</font>

</pre></body></html>